// pages/ranking/ranking.js
const config = require('../../config.js')
const http = require('../../http.js')
var page = 1
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isRefresh: false,
    noData: true,
    rankingData: []
  },

  /**l
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      cid: options.id
    })
    page = 1
    this.getMeetings(page)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  toHear: function (e) {
    wx.navigateTo({
      url: '../hear/hear?roomId='+e.currentTarget.dataset.id,
    })
  },

  bindscrolltolower: function () {
    console.log("bindscrolltolower")
    page++
    this.getMeetings(page)
  },

  bindrefresherrefresh: function () {
    console.log("bindrefresherrefresh")
    this.setData({
      isRefresh: true,
      noData:true
    })
    page = 1
    this.getMeetings(page)
  },


  getMeetings: function (p) {
    var that = this
    http.request(
      config.meetings,
      'POST', {
        page: p,
        pageSize: 20,
        orderType: 2,
        conferenceId: this.data.cid,
      },
      function (res) {
        if (res.data != null) {
          if (p == 1) {
            that.setData({
              rankingData: res.data
            })

            if(res.data.length > 0){
              that.setData({
                noData:false
              })
            }
          } else {
            that.setData({
              rankingData: that.data.rankingData.concat(res.data)
            })
          }
        }
        if (that.data.isRefresh) {
          that.setData({
            isRefresh: false
          })
        }
      },
      function (err) {
        wx.showToast({
          title: err,
          icon: 'none',
        })
      }, true
    )
  }
})